﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _12.享元模式
{
    class Program
    {
        static void Main(string[] args)
        {
            School school = new School();
            Student student = school.GetStudent(1);
            Console.WriteLine(student.ToString());
            student = school.GetStudent(2);
            Console.WriteLine(student.ToString());
            Console.ReadKey();

        }
    }

    public abstract class abStudent
    {
        public string Name;
        public string schName;
        public string Sex;
        public abStudent()
        {
            schName = "西南科技大学";
            Sex = "男";
        }

        public override string ToString()
        {
            return string.Format("我叫{0},性别{1},在读学校{2}", Name, Sex, schName);
        }
    }
    public class Student : abStudent
    {
        public Student(string name)
        {
            Name = name;
        }
    }
    public class School
    {
        private Dictionary<int, Student> StudentList;
        public School()
        {
            StudentList = new Dictionary<int, Student>();
            StudentList.Add(1, new Student("张三"));
            StudentList.Add(2, new Student("李四"));
        }
        public Student GetStudent(int num)
        {
            return StudentList[num] as Student;
        }
    }
}
